class MapElement extends GridBase {
	/**类型 */
	public type: MapElementType;
	static elements = {};
	public constructor() {
		super();
	}
	canBroken() {
		let data = this.getMapData(this.type);
		return data && data.canBroken;
	}
	getMapData(type: number) {
		return MapEleData[this.type];
	}
	static clear() {
		for (var key in this.elements) {
			this.elements[key] && this.elements[key].clear();
		}
		this.elements = {};
	}
	static getElement(index: number) {
		return this.elements[index];
	}
	/**损坏*/
	static breakElement(index: number) {
		let ele = this.getElement(index);
		if (ele && ele.canBroken()) {
			ele.clear();
		}
	}
	$onAddToStage(stage: egret.Stage, nestLevel: number) {
		let data = this.getMapData(this.type);
		this.img.source = data ? data.source + "_png" : "";
		let { x, y } = MapElement.index2pos(this.index);
		this.x = x, this.y = y;
		MapElement.elements[this.index] = this;
		super.$onAddToStage(stage, nestLevel);
	}
	$onRemoveFromStage() {
		delete MapElement.elements[this.index];
		super.$onRemoveFromStage();
	}

}

enum MapElementType {
	Null,
	Wall,
	Iron,
	River,
	OldHome
}

let MapEleData = {
	[MapElementType.Wall]: { source: "e1", canBroken: true },
	[MapElementType.Iron]: { source: "e2", canBroken: false }
}

let gridValue = 21;